//
//  SINAStueHomeCourseItemTableViewCell.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/16.
//  Copyright © 2018年  androidlongs. All rights reserved.
//
// 首页面 显示课程选项
// 1. 有设置圆角方面
// 2. 有设置阴影方面

#import "SINAStueHomeCourseItemTableViewCell.h"
#import "SINACircularBeadUtils.h"
#import "SINACalendarUtils.h"
#import "SINAViewShadowUtils.h"


@interface SINAStueHomeCourseItemTableViewCell()

@property (weak, nonatomic) IBOutlet UIView *backGrouncContentView;
//阴影
@property (weak, nonatomic) IBOutlet UIView *backGrouncShadowContentView;
@property (weak, nonatomic) IBOutlet UIButton *signButton;
@property (weak, nonatomic) IBOutlet UIImageView *signImageView;
//上
@property (weak, nonatomic) IBOutlet UIView *upDiviView;
//下
@property (weak, nonatomic) IBOutlet UIView *toDiviView;
//时间轴
@property (weak, nonatomic) IBOutlet UILabel *courseFlagTimeLabel;

@property (weak, nonatomic) IBOutlet UILabel *courseTimeLabel;

@property (weak, nonatomic) IBOutlet UILabel *courseNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *courseAdressLabel;

@property (weak, nonatomic) IBOutlet UIView *courseSignPrentView;



@end

@implementation SINAStueHomeCourseItemTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.courseSignPrentView.backgroundColor=[UIColor clearColor];
    [SINACircularBeadUtils makeCircularBead:4 andView:self.backGrouncContentView andIsSetBackground:NO];
    [SINACircularBeadUtils makeCircularBead:4 andView:self.signButton andIsSetBackground:NO];
    [SINAViewShadowUtils updateViewShadow:self.backGrouncShadowContentView andWithShadowWidth:0 andWithShadowHeight:2 andWithShadowColor:[UIColor blackColor] andWithShadowRadius:2];
}
- (IBAction)signClickButton:(UIButton *)sender {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)setModel:(SINAStuHomeCoursItemModel *)model{
    _model = model;
    
    
    
    //当前时间
    NSInteger currentTime = [[SINACalendarUtils currentTimeStr] integerValue];
    DLog(@"课程签到当前时间是 %ld",(long)currentTime);
    
    //课程开始时间
    NSInteger courseStartTime = [model.courseStartTime integerValue];
    DLog(@"课程签到当前时间是 courseStartTime %ld",(long)courseStartTime);
    //课程结束时间
    NSInteger courseEndTime = [model.courseEndTime integerValue];
    
    //开课前50分钟可签到
    NSInteger signStartTime = courseStartTime -1000*courseSignPreTime*60;
    NSInteger signEndTime = courseStartTime +1000*courseSignPreTime*60;
    DLog(@"课程签到当前时间是 signStartTime  %ld  %@ model.tstatus",(long)signStartTime,model.tstatus);
    
    
    
    
    
    if ([model.tstatus integerValue]==1000) {
        //未签到 可以签到
        self.signButton.hidden = NO;
        [self.signButton setTitle:@"签到" forState:UIControlStateNormal];
        [self.signButton setTitleColor:[UIColor colorWithHexString:@"#4F8FD7"] forState:UIControlStateNormal];
        
        if(currentTime<signStartTime){
            //未到签到时间
            [self.signButton setTitleColor:[UIColor colorWithHexString:@"#727272"] forState:UIControlStateNormal];
            self.signImageView.image=[UIImage imageNamed:@"home_sign_no_icon"];
        }else if (currentTime>=signStartTime&&currentTime<=signEndTime){
            //签到时间中
            self.signImageView.image=[UIImage imageNamed:@"home_sign_icon"];
        }else if (currentTime>signEndTime&&currentTime<courseEndTime){
            DLog(@"老师发起点名可签到");
            if (model.tecSignStartTime!=nil) {
                [self.signButton setTitleColor:[UIColor colorWithHexString:@"#727272"] forState:UIControlStateNormal];
                self.signImageView.image=[UIImage imageNamed:@"home_sign_no_icon"];
            }else{
                [self.signButton setTitleColor:[UIColor colorWithHexString:@"#4F8FD7"] forState:UIControlStateNormal];
                self.signImageView.image=[UIImage imageNamed:@"home_sign_icon"];
            }
            
        }else{
            [self.signButton setTitle:@"未签到" forState:UIControlStateNormal];
            [self.signButton setTitleColor:[UIColor colorWithHexString:@"#727272"] forState:UIControlStateNormal];
            self.signImageView.image=[UIImage imageNamed:@"home_sign_no_icon"];
        }
        
        self.courseSignPrentView.hidden = NO;
    } else {
        self.signButton.hidden = NO;
        [self.signButton setTitle:@"已签到" forState:UIControlStateNormal];
        self.signImageView.image=[UIImage imageNamed:@"home_sign_no_icon"];
        self.courseSignPrentView.hidden = YES;
    }
    
    
    
    
    
    
    if (self.pos==0) {
        self.upDiviView.hidden = YES;
    } else {
        self.upDiviView.hidden = NO;
    }
    if (self.pos==self.totalNumber-1) {
        self.toDiviView.hidden = YES;
    } else {
        self.toDiviView.hidden = NO;
    }
    
    
    self.courseNameLabel.text = model.courseTitle;
    
    if (model.tendtime!=nil) {
        self.courseTimeLabel.text=[NSString stringWithFormat:@"%@-%@",[SINACalendarUtils getDateStringWithTimeStr:model.tstarttime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:model.tendtime andFormat:@"HH:mm"]];
        
        self.courseAdressLabel.text=model.taddress;
        
        self.courseFlagTimeLabel.text = [NSString stringWithFormat:@"%@",[SINACalendarUtils getDateStringWithTimeStr:model.tstarttime andFormat:@"HH:mm"]];
    } else {
        self.courseTimeLabel.text=[NSString stringWithFormat:@"%@-%@",[SINACalendarUtils getDateStringWithTimeStr:model.courseStartTime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:model.courseEndTime andFormat:@"HH:mm"]];
        
        self.courseAdressLabel.text=model.courseLocation;
        
        self.courseFlagTimeLabel.text = [NSString stringWithFormat:@"%@",[SINACalendarUtils getDateStringWithTimeStr:model.courseStartTime andFormat:@"HH:mm"]];
    }
    
    WeakSelf;
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.courseSignPrentView andWithBlick:^(UIView *view) {
        if (self.itemCellBlock) {
            weakSelf.itemCellBlock(weakSelf.pos, 1, weakSelf.model);
        }
    }];
    
    
}

@end
